package com.xi.springboot.utils;

import org.springframework.cache.annotation.Cacheable;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: xjs
 * @Date: 2022/11/21/9:55
 * @Description:
 */
public class UrlUtils {
    //获取一个6位数字的随机字符串
    public static String getUrl(){
        //用字符串容器存储随机字符串
        StringBuilder stringBuilder = new StringBuilder();
        //创建Random对象
        Random r = new Random();
        //因为是5个字符的字符串，循环5次
        for (int i = 0; i < 5; i++) {
            //每次随机出0，1，2之间的任意一个数字
            int num = r.nextInt(3);
            switch (num) {
                //如果随机为0，则添加随机大写字母
                case 0:
                    char lowerChar = (char)(r.nextInt(26) + 65);
                    stringBuilder.append(lowerChar);
                    break;
                //如果随机为1，则添加随机小写字母
                case 1:
                    char upperChar = (char)(r.nextInt(26) + 97);
                    stringBuilder.append(upperChar);
                    break;
                //如果随机为2，则添加随机数字字符
                case 2:
                    char numChar = (char)(r.nextInt(10) + 48);
                    stringBuilder.append(numChar);
                    break;
            }
        }
        return stringBuilder.toString();
    }
    @Cacheable(value = "shortUrl",key="#url")
    public String get(String url){
        return null;
    }

}
